<template>
  <view class="body"  :style="{minHeight:screenHeight + 'px'}">
    <view class="background" />
    <view class="settlementBox">
      <!-- <view class="box" @tap="selectAddress">
        <view v-if="address.address">
          <view class="address" @change="">{{ address.address }}</view>
          <view class="user">{{ address.user }}&nbsp{{ address.phone  }}</view>
        </view>
        <view class="title address flex a-item" v-else @tap="selectAddress">请选择地址</view>
      </view> -->
      <view class="box">
        <view class="title">库存清单</view>
        <settlement-goods v-for="item in addstocklist" :goods="item"></settlement-goods>
      </view>
    </view>
    <!-- <uni-popup  mask-background-color="background-color: rgba(69,64,68);" ref="popup" type="bottom"  :animation="true">
      <select-address :address.sync="address" :customer="customer"  @close="close" />
    </uni-popup> -->
    <!-- <view class="mask" @touchmove.stop.prevent="" @tap="close" @close="close" v-if="mask">
      <view></view>
    </view> -->
    <view class="bottom">
      <view class="settlementBtm flex a-item ">
        <view class="price">
          <view>箱数:{{boxval}}</view>
          <view>零数:{{mainval}}</view>
        </view>
        <view class="settlement flex a-item j-content"  @tap="submitOrder">
        去提报
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import {getOpenId, getScreen, getUserInfo} from "../../service/auth";
import settlementGoods from "../components/settlementGoods";
import payMode from "../../components/payMode";
import selectAddress from "../components/selectAddress";
import {addOrSave, appletSalesOrderAddOrSave, getNearbyWarehouse,stockreport,newstockreport} from "../../service/api/shopping";
import {appletInviteRegisterCustomerAreaList} from "../../service/api/pay";
import {getBasWarehouseList} from "../../service/api/logistics";
import selectCoupon from "../components/selectCoupon";
export default {
  name: "index",
  components: {settlementGoods, payMode, selectAddress, selectCoupon},
  props:{
    type:{
      type:String,
    },
  },
  data(){
    return{
      addstocklist: [],
      url:'',
      mask:false,
      customerId: '',
      goodsId: null,
      goodsCount: null,
      customer:{},
      remark:'',
      screenHeight:0,
      location:'',
      appletExtraDict:[],
      warehouseList:[],
      warehouseId:'',
      currentLocation: '',
      user:{},
      news:'',
      photo:'',
      boxval:0,
      mainval:0,
      back:''
    }
  },
  computed:{
    getAmount(){
      this.boxval = this.addstocklist.reduce((prev,cur)=>prev+Number(cur.boxNum),0)
      this.mainval = this.addstocklist.reduce((prev,cur)=>prev+Number(cur.mainNum),0)
    }
  },
  onLoad(option){
this.news=option.news
this.photo=option.photo
this.back=option.back
  },
  created() {
    const app = getApp()
    this.addstocklist = app.globalData.addstocklist
    this.customer = app.globalData.selectedPosition
    const {height} = getScreen()
    this.screenHeight = height
    const data = getUserInfo()
    this.user = JSON.parse(data)
    getBasWarehouseList({page:1,size:100}).then(res=>{
    }).catch(err=>{
      this.warehouseList = err.content
    })

    this.appletExtraDict = app.globalData.appletExtraDict
  },
  methods:{
    submitOrder(){
      console.log(this.photo,'nnnnnnnnnsssssss');
      for (let i = 0; i < this.addstocklist.length; i++) {
        // console.log(this.addstocklist[i].goodsId);
        this.goodsId=this.addstocklist[i].goodsId
        this.goodsCount=this.addstocklist[i].goodsCount
      }
      
        if (!this.news) {
          const data = this.addstocklist.map(item=>({
        customerId: this.customer.id,
        goodsId:item.goodsId,
        goodsCount:item.goodsCount}))
          stockreport(data).then(res=>{
        this.sumber()
      }).catch(err=>{
        this.uniShowToast(err.msg)
      })
        }else{
          const data = this.addstocklist.map(item=>({
        customerId: this.customer.id,
        goodsId:item.goodsId, 
        goodsCount:item.goodsCount}))
        const dd={
          customerStockDtoList:data,
          visitedCustomerId:this.customer.id
        }
          newstockreport(dd).then(res=>{
        this.sumber()
      }).catch(err=>{
        this.uniShowToast(err.msg)
        }
        )}
      
    },
sumber(){
    uni.navigateBack({delta: 1})
         // 清空库存
         this.addstocklist.length = 0
},
    close(){
      this.$refs.popup.close()
      this.mask = false
    },
    // selectAddress(){
    //   this.$refs.popup.open()
    //   this.mask = true
    // },
  }
}
</script>

<style lang="scss" scoped>
.body{
  background: #F5F5F5;
  position: relative;
}
.background{
  background-image: linear-gradient(red,#F5F5F5);
  position: absolute;
  width: 100%;
  height: 500rpx;
  top: 0;
  z-index: 1;
}

.settlementBox{
  padding: 30rpx;
  position: relative;
  font-family: PingFangSC;
  z-index: 2;
  // .address{
  //   position: relative;
  //   &:after{
  //     content:">";
  //     position: absolute;
  //     right: 20rpx;
  //     color: rgb(205,205,205);
  //     font-size: 35rpx;
  //     top:20%
  //   }
  // }
  .box{
    .couponBox{
      height: 80rpx;
      position: relative;
      display: flex;
      margin-bottom: -30rpx;
      .couponReduceAmount{
        color: red;
        position: absolute;
        right: 80rpx;
      }
      .coupon{
        width: 40rpx;
        height: 40rpx;
        margin-right: 30rpx;
        background-image: linear-gradient(red,#F9645F);
        color: #ffffff;
        border-radius: 10rpx;

      }
      .couponName{
        &:after{
          content:">";
          position: absolute;
          right: 20rpx;
          color: rgb(205,205,205);
          font-size: 35rpx;
          top:20%
        }
      }
    }
  }
  .title{
    font-size: 35rpx;
    height: 80rpx;
  }

}
.commitScutomer{
  position: fixed;
  background-color: #ffffff;
  top: 30%;
  left: 20%;
  width: 450rpx;
  z-index: 999;
  border-radius: 25rpx;
  box-shadow: #555555 0 0 5px 1px;
}
.settlementBtm{
  width: 700rpx;
  background-image: linear-gradient(to right,#000000,#393939);
  color: #ffffff;
  height: 120rpx;
  border-radius: 120rpx;
  margin-bottom: 30rpx;
  font-size: 45rpx;
  .price{
    color: #ffffff;
    width: 300rpx;
    display: flex;
    // align-items: center;
    font-size: 30rpx;
    padding-left: 8%;
    flex-direction: column;
  }
}
.settlement{
  background: red;
  color: #ffffff;
  width: 200rpx;
  position: absolute;
  right: 0;
  height: 120rpx;
  border-radius: 0 200rpx 200rpx 0;
  font-size: 35rpx;
  bottom: 30rpx;
  margin-left: 10rpx;

}
.address{
  font-size: 40rpx;
  font-weight: 600;
}
.user{
  color: #666666;
}
.bottom{
  position: fixed;
  z-index: 90;
  left: 25rpx;
}
.remarkBox{
  .label{
    font-size: 35rpx;
    width: 200rpx;
  }
  input{
    width: 100%;
    height: 100%;
    font-size: 32rpx;
  }
}
</style>
